package com.yangwudongxi.sqlloghelper.dto;

import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * 数据库配置信息
 *
 * @author 氧屋东西
 */
@Data
public class DatabaseConfig {
    
    @NotBlank(message = "数据库地址不能为空")
    private String host = "test.yangwudongxi.com";
    
    @NotNull(message = "端口不能为空")
    private Integer port= 13306;
    
    @NotBlank(message = "用户名不能为空")
    private String username = "zdduser";
    
    @NotBlank(message = "密码不能为空")
    private String password ="Ywdx@2022";
    
    private String database ="esthetics";
    
    /**
     * 获取JDBC连接URL
     */
    public String getJdbcUrl() {
        StringBuilder url = new StringBuilder("jdbc:mysql://");
        url.append(host).append(":").append(port);
        
        if (database != null && !database.trim().isEmpty()) {
            url.append("/").append(database);
        }
        
        url.append("?useUnicode=true&characterEncoding=utf8&useSSL=true&serverTimezone=Asia/Shanghai");
        
        return url.toString();
    }
}